<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        nums1 = [4,9,5,8], nums2 = [9,4,9,8,4,5]
        function intersection(a, b) {
            const newArr = []
            for (let i = 0; i < a.length; i++) {
                // const element = array[o];
                if(b.includes(a[i])) {
                    newArr.push(a[i])
                }
                
            }
            return newArr
        };
        
        console.log(intersection(nums1, nums2));
    </script>
</body>

</html>